import java.time.LocalDate;
import java.time.LocalTime;

public class CustomerAction {
    private String userId;
    private LocalDate bookDate;
    private LocalTime beginTime;
    private LocalTime endTime;
    private String bookCourt;
    private boolean isCancel;

    public CustomerAction() {
        this.userId = null;
        this.bookDate = null;
        this.beginTime = null;
        this.endTime = null;
        this.bookCourt = null;
        this.isCancel = false;
    }

    public String getUserId() {
        return userId;
    }

    public LocalDate getBookDate() {
        return bookDate;
    }

    public LocalTime getBeginTime() {
        return beginTime;
    }

    public LocalTime getEndTime() {
        return endTime;
    }

    public String getBookCourt() {
        return bookCourt;
    }

    public boolean isCancel() {
        return isCancel;
    }

    // 用户名   预订日期      预订起始终止时间   预订场地   （取消标记）
    // U123     2016-06-02   20:00~22:00           A         (C)
    public void parseFromStringInputs(String[] inputs) {

        // 用户名
        this.userId = inputs[0];

        // 预订日期
        String dateStr = inputs[1];
        String[] dateParts = dateStr.split("-");
        int year = Integer.parseInt(dateParts[0]);
        int month = Integer.parseInt(dateParts[1]);
        int day = Integer.parseInt(dateParts[2]);
        this.bookDate = LocalDate.of(year, month, day);

        String timesStr = inputs[2];
        String[] timesArr = timesStr.split("~");

        // -----预订起始时间------
        String btimeStr = timesArr[0];
        String[] btimeParts = btimeStr.split(":");
        int btimeHour = Integer.parseInt(btimeParts[0]);
        int btimeMin = Integer.parseInt(btimeParts[1]);
        this.beginTime = LocalTime.of(btimeHour, btimeMin);

        // -----预订终止时间-----
        String etimeStr = timesArr[1];
        String[] etimeParts = etimeStr.split(":");
        int etimeHour = Integer.parseInt(etimeParts[0]);
        int etimeMin = Integer.parseInt(etimeParts[1]);
        this.endTime = LocalTime.of(etimeHour, etimeMin);

        // 预订场地
        this.bookCourt = inputs[3];

        // 判定是否为取消预订事件
        if (inputs.length == 4) {
            // Book Action
            this.isCancel = false;
        } else if (inputs.length == 5) {
            // Cancel Action
            this.isCancel = true;
        }
    }
}
